<template>

<van-icon
:color="attitude===-1?'#ffa500' : '#777'"
:name="attitude===1? 'good-job': 'good-job-o'"
@click="changeFollowed"
/>

</template>

<script>

import { getCommentsAPI } from '@/api/index.js'
export default {
  name: 'CollectArticle',
  props: {
    attitude: { // 收藏文章状态
      type: Number,
      default: -1
    },
    artId: { // 收藏文章id
      type: String,
      default: ''
    }

  },
  data () {
    return {
      btnLoading: false // 关注按钮的架子状态
    }
  },

  methods: {
    // 改变关注作者状态
    async changeFollowed () {
      console.log(1111)
      this.btnLoading = true
      try {
        if (this.attitude === 1) {
          // 已关注，取消关注
          await getCommentsAPI(this.artId)
        }
      } catch (err) {
        this.$toast('操作失败')
        console.log(err)
      }
      // 整个逻辑代码执行完后关闭加载状态
      this.btnLoading = false
    }
  }
}
</script>

<style>

</style>
